import { createStore } from 'vuex'
import axios from 'axios';
import { Axios } from '@/plugins/axiosInstance'
export default createStore({
  state: {
    userInfo: {
      account: "admin",
      password: "123"
    },
    residentList: [],
    //总数据
    totalnumber: [],
    //居民数量
    numresnum: [],
    //签约量
    contractnum: [],
    //服务量
    amountnum: [],
    //居民健康记录
    healthRecord: [],
    allHealthRecord: []
  },
  getters: {

  },
  mutations: {
    test(state) {
      console.log(123);

    },
    SETRESIDENT(state, payload) {
      state.residentList = payload

    },
    getSothedata(state, payload) {
      // state.totalnumber=payload
      state.totalnumber = payload
      // console.log(state.totalnumber)
    },
    residents(state, payload) {
      state.numresnum = payload
      // console.log(state.numresnum)
    },
    contract(state, payload) {
      state.contractnum = payload
    },
    amount(state, payload) {
      state.amountnum = payload
    },
    SETRECORD(state, payload) {
      state.healthRecord = payload
    },
    SETALLRECORD(state, payload) {
      state.allHealthRecord = payload
      console.log(state.allHealthRecord);

    }
  },
  actions: {
    getResidentInfo(context, val) {
      axios.get('http://localhost/getResidentInfo').then(res => {
        context.commit('SETRESIDENT', res.data)
      })
    },
    //总数量
    getSothedata(context, val) {
      axios.post('http://localhost/resident', { type: "total" }).then((res) => {
        // console.log(res)s
        context.commit('getSothedata', res.data.data)
      })
    },
    //居民总数量
    residents(context, val) {
      axios.post('http://localhost/resident', { type: "resnum" }).then((res) => {
        context.commit('residents', res.data.data)
      })
    },
    //签约量
    contract(context, val) {
      axios.post('http://localhost/resident', { type: "signum" }).then((res) => {
        context.commit('contract', res.data.data)
      })
    },
    //服务量
    amount(context, val) {
      axios.post('http://localhost/resident', { type: "sernum" }).then((res) => {
        context.commit('amount', res.data.data)
      })
    },
    //获取居民健康记录信息
    getHealthRecord(context, val) {
      Axios.post('getHealthRecordById', {
        id: val
      }).then(res => {

        context.commit('SETRECORD', res.data)
      })
    },
    getAllHealthRecordById(context, val) {
      Axios.post('getAllHealthRecordById', {
        id: val
      }).then(res => {
        console.log(res.data);

        context.commit('SETALLRECORD', res.data)

      })
    },

  },
  modules: {
  }
})
